package my.jwds.p23;

import my.jwds.p21.ListNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MergeKLists {

    public static void main(String[] args) {

        Solution obj = new Solution();
        long start = System.currentTimeMillis();
        System.out.println("运行时间:" + (System.currentTimeMillis() - start));
    }

    static class Solution {


        public ListNode mergeKLists(ListNode[] lists) {
            List<Integer> nums = new ArrayList<>();
            for (ListNode list : lists) {
                while(list != null){
                    nums.add(list.val);
                    list = list.next;
                }
            }
            Collections.sort(nums);
            ListNode res = new ListNode();
            ListNode temp = res;
            for (Integer num : nums) {
                temp.next = new ListNode(num);
                temp = temp.next;
            }
            return res.next;
        }
    }
}